﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace DC2010.Manager
{
    public class ResourceManager
    {
        private Dictionary<string, string> dict = new Dictionary<string, string>();
        public void Init(string language)
        {
            ReadCsv(language);
        }

        public void ReadCsv(string language)
        {
            dict.Clear();

            if (!File.Exists("data\\resources_" + language + ".txt")) return;

            using (TextReader tr = new StreamReader("data\\resources_" + language + ".txt"))
            {
                string s = tr.ReadLine();

                while (s != null)
                {

                    string[] sField = s.Split(';');

                    if (sField.GetLength(0) == 2)
                    {
                        //we have key and value
                        dict.Add(sField[0], sField[1]);
                    }

                    s = tr.ReadLine();

                }
            }
        }

        public string this[string key]
        {
            get
            {
                if (dict.ContainsKey(key))
                    return dict[key];

                return "MESSAGE NOT FOUND IN RESOURCE FILE!!!";
            }
        }
    }
}
